#include <stdio.h>
#include <stdlib.h>

int insert_head(int value, int * parray, int length)
{
  int i;
  int temp, second;

  for (i = length; i > 0; i--) {
    parray[i] = parray[i-1];
  }

  parray[0] = value;

  return 0;
}


int insert_position(int position, int value, int * parray, int length)
{
  int i;

  for (i = length; i > 0; i--) {
    if ( i == position-1) {
      parray[position-1] = value;
      break;
    }
    parray[i] = parray[i-1];
  }

  return 0;
}

int remove_position(int position, int * parray, int length)
{
  int i;

  for (i = 0; i < length; i++) {
    if ( i == position-1) {
      parray[position-1] = parray[i];
      for (; i < length; i++) {
	parray[i] = parray[i+1];
      }
      break;
    }
  } 
  
  return 0;
}

int remove_position_another(int position, int * parray, int length)
{
  int i;

  for (i = position; i < length; i++) {
    parray[i] = parray[i+1];
  }

  return 0;
}

void delete_item(int item, int * parray, int length)
{
  int i, j;

  for (i = 0; i < length; i++) {
    if (parray[i] == item) {
      for (j = i; j < length; j++) {
	parray[j] = parray[j+1];
      }
    }
  }
}

int putout(int length, int * parray)
{
  int i;

  for (i = 0; i < length; i++){
    printf(" %d", parray[i]);
    if (i == 10-1)
      printf("\n");
  }
  printf("\n");
}

int main(void)
{
  int array[100] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  int position, value, length;

  position = 8;
  value = 77;
  length = 20;
  //insert_head(value, array, length);
  insert_position(position, value, array, length); 
  length = 20;
  putout(length, array);

  position = 8;
  remove_position(position, array, length);
  length = 20;
  putout(length, array);

  position = 4;
  remove_position_another(position, array, length);
  length = 20;
  putout(length, array);

  return 0;
}

